package downbody

import (
	"bytes"
	"encoding/binary"
	"gitee.com/Cookie_XiaoD/go-terminalserver/protocol/std808core/body"
)

//终端注册应答
type TerminalRegRespBody struct {
	SerialNumber uint16
	Result       body.RegisterResult
	AuthCode     string
}

func NewTerminalRegRespBody(sn uint16, ret body.RegisterResult, authcode string) *TerminalRegRespBody {
	return &TerminalRegRespBody{
		SerialNumber: sn,
		Result:       ret,
		AuthCode:     authcode,
	}
}

func (body *TerminalRegRespBody) To808Bytes() []byte {
	var err error
	writer := new(bytes.Buffer)
	err = binary.Write(writer, binary.BigEndian, body.SerialNumber)
	err = binary.Write(writer, binary.BigEndian, body.Result)
	writer.Write([]byte(body.AuthCode))
	if err != nil {
		return nil
	}
	return writer.Bytes()

}
